﻿@using CodeCamp.Models.Schedule
@using CodeCamp.Models.Shared
@using CodeCamp.Infrastructure.Extensions
@model ScheduleGridModel

<table class="sessionGrid">
    <tr>
        <td style="vertical-align:bottom;">Timeslot</td>
    @foreach (var roomKV in Model.Rooms
        .OrderBy(kv => kv.Value.Building)
        .ThenBy(kv => kv.Value.Floor)
        .ThenBy(kv => kv.Value.RoomName))
    {
        <td>
        @if (Model.BuildingCount > 1)
        {
            @roomKV.Value.Building<br />@roomKV.Value.RoomName
            if ((Model.CapacityCount > 0) || (Model.FloorCount > 1))
            {
            <br />
                if ((Model.FloorCount > 1) && roomKV.Value.Floor.HasValue)
                {
                    <text>floor: @roomKV.Value.Floor.Value</text>
                }
                if (roomKV.Value.Capacity > 0)
                {
                    <text>(seats @roomKV.Value.Capacity)</text>
                }
            }
        }
        else
        {
            @roomKV.Value.RoomName
            if ((Model.CapacityCount > 0) || (Model.FloorCount > 1))
            {
            <br />
                if ((Model.FloorCount > 1) && roomKV.Value.Floor.HasValue)
                {
                    <text>floor: @roomKV.Value.Floor.Value</text>
                }
                if (roomKV.Value.Capacity > 0)
                {
                    <text>(seats @roomKV.Value.Capacity)</text>
                }
            }
        }
        @if (!roomKV.Value.ShowToPublic)
        {
            <text><br />NOT PUBLIC</text>
        }
        </td>
    }
    </tr>
    @foreach (var timeslotKV in Model.Timeslots.OrderBy(kv => kv.Value.StartTime))
    {
        <tr>
            <td>
            @timeslotKV.Value.StartTime.ToShortTimeString()
            @if (timeslotKV.Value.SessionCount > 0)
            {
                <text> &ndash; @timeslotKV.Value.EndTime.ToShortTimeString()</text>
            }

            </td>
            @if (timeslotKV.Value.SessionCount == 0)
            {
                <td colspan="@Model.Rooms.Count.ToString()">@timeslotKV.Value.Name</td>
            }
            else
            {
                foreach (var cell in timeslotKV.Value.GridCells
                    .OrderBy(c => c.Value.CellRoom.Building)
                    .ThenBy(c => c.Value.CellRoom.Floor)
                    .ThenBy(c => c.Value.CellRoom.RoomName))
                {
                    if (cell.Value.CellRoom.ShowToPublic || User.IsInRole(CCRoles.RoleNames.BigCheeze))
                    {
                    <td>
                    @{
                        var firstCell = true;
                        foreach(var session in cell.Value.Sessions)
                        {
                            if (firstCell) { firstCell = false; }
                            else { <br /> }
                            @Html.ActionLink(session.Title.TruncateWithElipses(60), "Details", "Sessions", new { eventName = Model.EventShortName, id = session.SessionId }, null)
                        }
                    }
                    </td>
                    }
                }
            }
        </tr>
    }
</table>    
